<?php

use yii\helpers\Html;

$this->title = '仔猪增长异常统计';
use backend\assets\PrintAsset;
PrintAsset::register($this);
use backend\modules\statistics\assets\EchartsAsset;
EchartsAsset::register($this);
\backend\assets\FullcalendarAsset::register($this);
?>

<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
            <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>

<div class="row">
    <div class="col-md-10 col-md-offset-1" style="margin-top: 70px">
        <button class="btn btn-primary btn-sm" style="margin-bottom: 10px" id="print">打印</button>
        <!--work progress start-->
        <section class="panel">
            <div class="panel-body progress-panel">
                <div class="task-progress">
                    <h1>有过巡检的</h1>
                </div>
                <div class="task-option">
                </div>
            </div>

            <table class="table table-hover">
                <tbody>
                    <tr>
                        <th>
                            业务员
                        </th>
                        <th>
                            待巡检仔猪数
                        </th>
                        <th>
                            管理仔猪总数
                        </th>
                        <th>
                            最后一次巡检时间
                        </th>
                        <th>
                            巡检周期
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>

                    <?php foreach ($list as $key => $row)  {?>
                        <tr>
                            <td>
                                <?= $row['business_person'] ?>
                            </td>
                            <td>
                                <?= $row['num'] ?>
                            </td>
                            <td>
                                <?= $row['total'] ?>
                            </td>
                            <td>
                                <?= $row['createtime']; ?>
                            </td>
                            <td>
                                <?= \common\models\sys\SysSetting::getValue('inspection_cycle')?>天
                            </td>
                            <td>
                                <button class="btn btn-primary btn-xs" id="sendmsg">通知巡检</button>
                                <button class="btn btn-success btn-xs detail" data-personid="<?= $key ?>" data-type="has" data-toggle="modal" data-target="#detail-model">查看详情</button>
                                <button class="btn btn-success btn-xs calder" data-personid="<?= $key ?>" data-type="has" data-toggle="modal" data-target="#calder-model">巡检日历</button>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </section>

        <section class="panel">
            <div class="panel-body progress-panel">
                <div class="task-progress">
                    <h1>从未巡检的</h1>
                </div>
                <div class="task-option">
                </div>
            </div>

            <table class="table table-hover">
                <tbody>
                <tr>
                    <th>
                        业务员
                    </th>
                    <th>
                        待巡检仔猪数
                    </th>
                    <th>
                        管理仔猪总数
                    </th>
                    <th>
                        最后一次巡检时间
                    </th>
                    <th>
                        巡检周期
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
                <?php foreach ($list2 as $key => $row)  {?>
                    <tr>
                        <td>
                            <?= $row['business_person'] ?>
                        </td>
                        <td>
                            <?= $row['num'] ?>
                        </td>
                        <td>
                            <?= array_key_exists($key,$total)?$total[$key]['total']:0 ?>
                        </td>
                        <td>
                            <?= '从未巡检' ?>
                        </td>
                        <td>
                            <?= $recycle_day?>天
                        </td>
                        <td>
                            <button class="btn btn-primary btn-xs" id="sendmsg" data-personid="<?= $key ?>" >通知巡检</button>
                            <button class="btn btn-success btn-xs detail" data-personid="<?= $key ?>" data-type="no" data-toggle="modal" data-target="#detail-model">查看详情</button>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
        </section>
        <!--work progress end-->
    </div>


    <!--统计图-->
    <div class="row">
        <div class="col-md-5" id="bingtu" style="widows:200px;height: 200px">

        </div>
    </div>

</div>



<div id="detail-model" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">巡检异常详情</h4>
            </div>
            <div class="modal-body" style="overflow: scroll;height: 700px;">
                正在加载。。。。。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->





<div id="calder-model" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">巡检日历</h4>
            </div>
            <div class="modal-body" style="overflow: scroll;height: 700px;">
                正在加载。。。。。
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</section>
</section>



<script>
    <?php $this->beginBlock('bingtu') ?>


    // 基于准备好的dom，初始化echarts实例
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'left',
            data:[]
        },
        series: [
            {
                name:'得病率',
                type:'pie',
                radius: ['50%', '70%'],
                avoidLabelOverlap: false,
                label: {
                    normal: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        show: true,
                        textStyle: {
                            fontSize: '12',
                        }
                    }
                },
                labelLine: {
                    normal: {
                        show: false
                    }
                },
                data:[
                    {'name':'待巡检',value:20},
                    {'name':'巡检',value:20},
                ]
            }
        ]
    };

//    var myChart = echarts.init(document.getElementById('bingtu'));
//    myChart.setOption(option);

    <?php $this->endBlock('bingtu') ?>
    <?php $this->registerJs($this->blocks['bingtu'],\yii\web\View::POS_END) ?>
</script>


<script>
    <?php $this->beginBlock('pignum') ?>
        $(function(){
            $('.detail').click(function(){
                if($(this).data('type') == 'has'){
                    var url = 'has-inspection-detail';
                }else{
                    var url = 'no-inspection-detail';
                }
                $.get(url,{personid:$(this).data('personid')},function(res){
                    $('#detail-model .modal-body').html(res);
                    $('#detail-model').modal('show');
                })

            })

            $('.calder').click(function(){

                $.get('/statistics/pig/datashow-inspection',{personid:$(this).data('personid')},function(res){
                    $('#calder-model .modal-body').html(res);
                    $('#calder-model').modal('show');
                })
            })

        })
    <?php $this->endBlock('pignum') ?>
    <?php $this->registerJs($this->blocks['pignum'],\yii\web\View::POS_END) ?>
</script>



<script>
    <?php $this->beginBlock('js_end') ?>

    //打印
    $(function(){
        $("#print").printPreview({
            obj2print:'#main-content',
            width:'810'
        });

    });


    //发消息通知
    $('#sendmsg').click(function(){
        $.post('sendmsg',{personid:$(this).data('personid')},function(){

        },'json');
    })
    <?php $this->endBlock('jsend') ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>

</script>







